﻿
@{
    ViewBag.Title = "HospitalEdit";
    Layout = "~/Views/Shared/layoutCommon.cshtml";
}
@model OF.Component.Model.HospitalInfo
@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }

            .col-sm-3 select {
                float: left;
                width: 145px;
                margin-left: 5px;
            }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">医院名称：</label>
                        <div class="col-sm-3">
                            <input class="form-control" style="width:300px;" @ViewBag.NameRead value="@Model.HospitalName" maxlength="50" name="name" id="name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">拼音首字母：</label>
                        <div class="col-sm-3">
                            <input class="form-control" style="width:300px;" value="@Model.Initial" maxlength="50" name="txtInitial" id="txtInitial" />
                        </div>
                    </div>
                    <div data-toggle="distpicker" class="form-group" data-value-type="code">
                        <label class="col-sm-2 control-label" for="name">所在城市：</label>
                        <div class="col-sm-3">
                            <select name="ProvinceID" id="ProvinceID" class="form-control" data-province="@Model.ProvinceId"></select>
                            <select name="CityID" id="CityID" class="form-control" data-city="@Model.CityID"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">医院地址：</label>
                        <div class="col-sm-3">
                            <textarea type="text" rows="4" class="form-control" style="width:300px;" maxlength="2000" name="address" id="address">@Model.Address</textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script type="text/javascript">
        $(document).ready(function () {
            initFormValidate();
            $("#btnSave").click(function () {
                save();
            });
            $("#cancel").click(function () {
                BMCW.closeTopLayer();
            });
        });
        function initFormValidate() {
            $("#form1").bootstrapValidator({
                submitHandler: function (valiadtor, loginForm, submitButton) {
                    valiadtor.defaultSubmit();
                },
                fields: {
                    name: {
                        validators: {
                            notEmpty: {
                                message: '医院名称不能为空'
                            }
                        }
                    },
                    txtInitial: {
                        validators: {
                            notEmpty: {
                                message: '拼音首字母不能为空'
                            }
                        }
                    },
                    CityID: {
                        validators: {
                            notEmpty: {
                                message: '请选择城市'
                            }
                        }
                    },
                    address: {
                        validators: {
                            notEmpty: {
                                message: '医院地址不能为空'
                            }
                        }
                    },
                }
            });
        }

        function save() {
            var bootstrapValidator = $("#form1").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                BMCW.ajax({
                    url: '@Url.Action("HospitalSave", "BasicData")',
                    type: "Post",
                    data: {
                        HospitalID: '@Model.HospitalID',
                        HospitalName: $("#name").val(),
                        Address: $("#address").val(),
                        ProvinceId: $("#ProvinceID").val(),
                        CityID: $("#CityID").val(),
                        Initial: $("#txtInitial").val()
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("保存成功", function () {
                                BMCW.getTopSelectedWin().search();
                            });
                        } else {
                            BMCW.alert("保存失败");
                        }
                    }
                });
            }
        }
    </script>
}

